using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using Utility;

public partial class Admin_diadiemlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
    }
    private void LoadData()
    {
        Pager.PageSize = 5;
        Criteria c = new Criteria();

        int total = 0;
        tbdiadiemcollection diadiemcollection =
        tbdiadiemBUS.Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
        diadiemcolumns.madiadiem.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = diadiemcollection;
        Repeater1.DataBind();

        Pager.ItemCount = total;
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
           e.Item.ItemType == ListItemType.Item)
        {
            tbdiadiem diadiem = (tbdiadiem)e.Item.DataItem;
            HyperLink hyp_tendoanhnghiep = (HyperLink)e.Item.FindControl("hyp_tendoanhnghiep");
            hyp_tendoanhnghiep.Text = diadiem.Tendiadiem;
            hyp_tendoanhnghiep.NavigateUrl = "~/Admin/diadiemdetail.aspx?id=" + diadiem.Madiadiem.ToString();

            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "~/Admin/diadiemupdate.aspx?id=" + diadiem.Madiadiem.ToString();
        }
    }
    protected void lbt_Xoa_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbdiadiem diadiem = tbdiadiemBUS.GetByID(id);
                tbdiadiemBUS.Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
}
